package com.lanjiyin.cloud.question.frount.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lanjiyin.cloud.api.dto.QuestionDto;
import com.lanjiyin.cloud.api.entity.PassportTikuClassify;
import com.lanjiyin.cloud.api.vo.QuestionChapterCommonVo;
import com.lanjiyin.cloud.api.vo.QuestionChapterVo;
import com.lanjiyin.cloud.question.biz.PassportTikuClassifyBiz;
import com.lanjiyin.cloud.question.mapper.QuestionMapper;

@Service
public class QuestionService {
	
	
	@Autowired
	private PassportTikuClassifyBiz  passportTikuClassifyBiz;
	
	@Autowired
	private QuestionMapper questionMapper;
	
	public List<QuestionChapterVo> selectList(QuestionDto questionDto){
		 String  prefix ="ljy_";
		//获取分类信息
		PassportTikuClassify passportTikuClassify = new PassportTikuClassify();
		passportTikuClassify.setApp_id(questionDto.getApp_id());
		passportTikuClassify.setApp_type(questionDto.getApp_type());
		passportTikuClassify = passportTikuClassifyBiz.selectOne(passportTikuClassify);
		if(null != passportTikuClassify) {
			//切割字符串获取数据库前缀
			String[] str = questionDto.getApp_id().split("_");
			//拼接字符串获取表名
			StringBuffer stringBuffer = new StringBuffer();
			String table = stringBuffer.append(prefix).append(str[0]).append(".").append(prefix).append(questionDto.getApp_type()).append("_").append(questionDto.getTab_key()).toString();
			questionDto.setTable(table);	
			//发起查询
			List<QuestionChapterCommonVo> list = questionMapper.selectList(questionDto);
			QuestionChapterVo questionChapterVo = new QuestionChapterVo();
			List<QuestionChapterVo> lists = new ArrayList<>();
			questionChapterVo.setList(list);
			questionChapterVo.setQuestion_tab(passportTikuClassify.getQuestion_tab());
			lists.add(questionChapterVo);
			return lists;
		}
		
		return null;
		
	}
	

}
